package com.briup.mt.service.impl;

import com.briup.mt.bean.Comment;
import com.briup.mt.bean.CommentExample;
import com.briup.mt.dao.CommentMapper;
import com.briup.mt.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.List;
    @Service
    public class CommentServiceImpl implements ICommentService {
    @Resource
    private CommentMapper commentMapper;

    @Override
    public List<Comment> query(String content) {
        CommentExample example=new CommentExample();
        if (!StringUtils.isEmpty(content)) {
            example.createCriteria().andContentLike("%" + content + "%");
        }
        List<Comment>list=commentMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Comment comment) {
        if (comment.getId() == null) {
            commentMapper.insert(comment);
        } else {
            commentMapper.updateByPrimaryKey(comment);
        }
    }

    @Override
    public void deleteById(long id) {
        commentMapper.deleteByPrimaryKey(id);
    }
}